package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageBsaCbaTemplateBaseVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageBsaCbaTemplateCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageBsaCbaTemplatePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageBsaCbaTemplateRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageBsaCbaTemplateUpdateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbatemplatevo.VoyageCbaTemplateHistoryVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBsaCbaTemplateDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBsaCbaTemplateService;


/**
 * 分类舱位自动批舱模版前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 分类舱位自动批舱模版")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bsaCbaTemplate")
public class VoyageBsaCbaTemplateController {

    @Resource
    private VoyageBsaCbaTemplateService voyageBsaCbaTemplateService;

    @Operation(summary = "创建分类舱位自动批舱模版")
    @PostMapping("/create")
    public CommonResult<Void> createVoyageBsaCbaTemplate(@Valid @RequestBody VoyageBsaCbaTemplateCreateReqVO createReqVO) {
        voyageBsaCbaTemplateService.createVoyageBsaCbaTemplate(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新分类舱位自动批舱模版")
    @PostMapping("/update")
    public CommonResult<Void> updateVoyageBsaCbaTemplate(@Valid @RequestBody VoyageBsaCbaTemplateUpdateReqVO updateReqVO) {
        voyageBsaCbaTemplateService.updateVoyageBsaCbaTemplate(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除分类舱位自动批舱模版")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBsaCbaTemplate(@PathVariable("id") Long id) {
        voyageBsaCbaTemplateService.deleteVoyageBsaCbaTemplate(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得分类舱位自动批舱模版")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaCbaTemplateRespVO> getVoyageBsaCbaTemplate(@PathVariable("id") Long id) {
        VoyageBsaCbaTemplateDO voyageBsaCbaTemplate = voyageBsaCbaTemplateService.getVoyageBsaCbaTemplate(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBsaCbaTemplate, VoyageBsaCbaTemplateRespVO.class));
    }

    @Operation(summary = "获得分类舱位自动批舱模版列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VoyageBsaCbaTemplateRespVO>> getVoyageBsaCbaTemplateList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBsaCbaTemplateDO> list = voyageBsaCbaTemplateService.getVoyageBsaCbaTemplateList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBsaCbaTemplateRespVO.class));
    }

    @Operation(summary = "获得分类舱位自动批舱模版分页")
    @PostMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBsaCbaTemplateRespVO>> getVoyageBsaCbaTemplatePage(@RequestBody @Valid VoyageBsaCbaTemplatePageReqVO pageVO) {
        PageResult<VoyageBsaCbaTemplateDO> pageResult = voyageBsaCbaTemplateService.getVoyageBsaCbaTemplatePage(pageVO);
        List<VoyageBsaCbaTemplateRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBsaCbaTemplateRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @Operation(summary = "获得分类舱位自动批舱模版")
    @PostMapping("/existTemplate")
    public CommonResult<List<VoyageBsaCbaTemplateRespVO>> getTemplateExistCba(@RequestBody @Valid VoyageBsaCbaTemplateBaseVO bsaCbaTemplateBaseVO) {
        List<VoyageBsaCbaTemplateDO> voyageBsaCbaTemplates = voyageBsaCbaTemplateService.getTemplateExistCba(bsaCbaTemplateBaseVO);
        return CommonResult.success(BeanUtil.copyToList(voyageBsaCbaTemplates, VoyageBsaCbaTemplateRespVO.class));
    }

    @Operation(summary = "从历史模板信息复制")
    @PostMapping("/createFromTem")
    public CommonResult<Void> copyFromTemplateHistory(@Valid @RequestBody VoyageCbaTemplateHistoryVO templateHistoryVO) {
        voyageBsaCbaTemplateService.copyFromTemplateHistory(templateHistoryVO);
        return CommonResult.success();
    }

}
